package org.ainlolcat.ainscience.statistics.handlers.hitran.instfunc;

import static java.lang.Math.pow;

/**
 * @author ainlolcat
 * Date: 11/21/13
 */
public class InvsPolyFunction implements InstrumentalFunction{
    double y0;
    double w;
    double A;
    double A1;
    double A2;
    double A3;

    public InvsPolyFunction() {
    }

    public InvsPolyFunction(double y0, double w, double a, double a1, double a2, double a3) {
        this.y0 = y0;
        this.w = w;
        this.A = a;
        this.A1 = a1;
        this.A2 = a2;
        this.A3 = a3;
    }

    public void setParameters(double[] params) {
        this.y0 = params[0];
        this.w = params[1];
        this.A = params[2];
        this.A1 = params[3];
        this.A2 = params[4];
        this.A3 = params[5];
    }

    //y0+A/(1 + A1*(2*(x-xc)/w)^2 + A2*(2*(x-xc)/w)^4 + A3*(2*(x-xc)/w)^6)
    public double getValue(double dx) {
        return y0 + A /(
                1 +
                A1 * pow(2*dx/w,2) +
                A2 * pow(2*dx/w,4) +
                A3 * pow(2*dx/w,6)
        );
    }
}
